package back.services;

import java.io.IOException;
import java.net.Socket;

import utils.helpers.logging.LineLog;

public class Telnet {
	public static boolean execute(String host, int portNumber) {
		Socket client;
		LineLog linelog = new LineLog();
		try {
			client = new Socket(host, portNumber);
			linelog.addpair("OK", "OK");
			linelog.addpair("LOCAL PORT", Integer.toString( client.getLocalPort() ) );
			client.close();
		} catch (IOException e) {
			//System.out.println(e);
			linelog.addpair("OK", "KO");
			linelog.addpair("ERROR", e.getLocalizedMessage() );
			return false;
		}
		finally {
		linelog.addpair("REMOTE PORT", Integer.toString( portNumber ) ) ;
		linelog.out();
		}
		return true;
	}
}
